from urllib.parse import quote_plus

import pandas as pd
from sqlalchemy import create_engine


def mysql_config():
    user = 'live_data'
    password = quote_plus('CJMg2tsHg7sj6bo0UTKq0a4T!fPDpJ')
    # passwd ='merchantsasd123!@%&'
    host = 'rm-bp17r99475xuauk63yo.mysql.rds.aliyuncs.com'
    # port1 ='3306'
    dbname2 = 'live_data'
    engine2 = create_engine(f"mysql+pymysql://{user}:{password}@{host}:3306/{dbname2}?charset=utf8mb4")
    return engine2


def xhs_user_info_bf():
    data = pd.read_sql('select * from live_data.xhs_user_info',mysql_config())
    print(data)
    data.to_csv("xhs_user_info_beifen.csv")

    import datetime
    print(datetime.datetime.now())
    return "备份执行完成"

# data = pd.read_csv("xhs_user_info.csv")
# pd.io.sql.to_sql(data, 'xhs_user_info', mysql_config(), schema='live_data',if_exists='append',index=False)
